package com.evan.review.stickytop;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.evan.review.R;
import java.util.List;

/**
 * 吸顶效果演示的RecyclerView适配器
 */
public class StickyContentAdapter extends RecyclerView.Adapter<StickyContentAdapter.ViewHolder> {

    private List<String> dataList;

    public StickyContentAdapter(List<String> dataList) {
        this.dataList = dataList;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_sticky_content, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        String content = dataList.get(position);
        holder.textContent.setText(content);
        
        // 为第一个和最后一个item添加特殊样式
        if (position == 0) {
            holder.itemView.setPadding(16, 24, 16, 8);
        } else if (position == dataList.size() - 1) {
            holder.itemView.setPadding(16, 8, 16, 24);
        } else {
            holder.itemView.setPadding(16, 8, 16, 8);
        }
    }

    @Override
    public int getItemCount() {
        return dataList != null ? dataList.size() : 0;
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView textContent;

        ViewHolder(@NonNull View itemView) {
            super(itemView);
            textContent = itemView.findViewById(R.id.text_content);
        }
    }
} 